<template>
	<el-form ref="form" :model="form" label-width="80px">
		<el-form-item label="用户名">
			<el-input v-model="form.username"></el-input>
		</el-form-item>
		<el-form-item label="密码">
			<el-input v-model="form.password"></el-input>
		</el-form-item>

		<el-form-item>
			<el-button type="primary" @click="onSubmit">登录</el-button>
			<el-button>取消</el-button>
		</el-form-item>
	</el-form>

</template>

<script>
	import axios from "axios"

	export default {
		data() {
			return {
				form: {
					username: '',
					password: ''
				}
			}
		},
		methods: {
			onSubmit() {
				console.log('submit!');
				axios.post('http://localhost:9080/v1/user/login', this.form).then(res => {
					console.log(res)
					//{code: 0, message: 'ERROR', data: '登陆失败'}
					//res.data
					if (res.data.code == 1) {
						alert("成功");
						this.$router.push({
							path: '/index'
						})
					} else {
						alert("登录失败,请检查账户或者密码");
					}
				})

				//this.$router.push({path:'/index'})
			}
		}
	}
</script>

<style>

</style>